package xyz.sunne.exception;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import xyz.sunne.response.ResponseCode;

import java.io.Serializable;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RequestException extends RuntimeException implements Serializable {
    private Integer code;
    private String msg;
    private Exception e;

    public RequestException(ResponseCode responseCode, Exception e) {
        this.code = responseCode.code;
        this.msg = responseCode.msg;
        this.e = e;
    }


    public RequestException(ResponseCode responseCode) {
        this.code = responseCode.code;
        this.msg = responseCode.msg;
    }

    public static RequestException authFail(String msg){
        return RequestException.builder()
                .code(ResponseCode.AUTHORIZATION_EXCEPTION.code)
                .msg(msg)
                .build();
    }

    public static RequestException fail(String msg){
        return RequestException.builder()
                .code(ResponseCode.FAIL.code)
                .msg(msg)
                .build();
    }

    public static RequestException fail(String msg,Exception e){
        return RequestException.builder()
                .code(ResponseCode.FAIL.code)
                .msg(msg)
                .e(e)
                .build();
    }

    public static RequestException fail(Integer code,String msg,Exception e){
        return RequestException.builder()
                .code(code)
                .msg(msg)
                .e(e)
                .build();
    }
}
